package com.xyy.saas.payment.service.impl;

import com.xyy.saas.payment.dao.mapper.EntrustPayInfoMapper;
import com.xyy.saas.payment.dao.model.EntrustPayInfo;
import com.xyy.saas.payment.service.EntrustPayInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class EntrustPayInfoServiceImpl implements EntrustPayInfoService {

    @Autowired
    private EntrustPayInfoMapper entrustPayInfoMapper;

    /**
     * 根据条件查询签约信息
     *
     * @param param
     * @return
     */
    @Override
    public List<EntrustPayInfo> selectByParam(EntrustPayInfo param) {
        return this.entrustPayInfoMapper.selectByParam(param);
    }

    /**
     * 根据协议编号查询签约信息
     *
     * @param contractCode
     * @return
     */
    @Override
    public EntrustPayInfo selectByContractCode(String contractCode) {
        if(StringUtils.isEmpty(contractCode) || "".equals(contractCode.trim())) {
            return null;
        }
        return this.entrustPayInfoMapper.selectByContractCode(contractCode);
    }

    /**
     * 插入
     *
     * @param entity
     * @return
     */
    @Override
    public EntrustPayInfo insertSelective(EntrustPayInfo entity) {
        if(null == entity) {
            throw new RuntimeException("参数为空!");
        }
        int rows = this.entrustPayInfoMapper.insertSelective(entity);
        if(rows < 1) {
            throw new RuntimeException("插入签约记录失败!");
        }
        return entity;
    }

    /**
     * 更新
     *
     * @param entity
     * @return
     */
    @Override
    public int updateByPrimaryKeySelective(EntrustPayInfo entity) {
        if(null == entity || null == entity.getId()) {
            throw new RuntimeException("参数或ID为空!");
        }
        return this.entrustPayInfoMapper.updateByPrimaryKeySelective(entity);
    }

    /**
     * 逻辑删除
     *
     * @param id
     * @return
     */
    @Override
    public int deleteByPrimaryKey(Long id) {
        if(null == id) {
            throw new RuntimeException("ID为空!");
        }
        return this.entrustPayInfoMapper.deleteByPrimaryKey(id);
    }

}
